<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        // 声明
        // yield：分隔符
        function* gen() {
            // console.log('hello generator')

            console.log(11)
            yield 'js';

            console.log(22)
            yield 'java';

            console.log(33)
            yield 'css'
        }

        let g = gen();
        console.log(g);
        console.log(g.next());
        console.log(g.next());
        console.log(g.next());
        console.log(g.next());
        console.log('---------------')

        for (const iter of gen()) {
            console.log(iter)
        }

    </script>
</body>
</html>